/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/******************************************************************************
 * Name: dog_micro_service_container.h
 *
 * Purpose: micro service model(container module) implementation for puppy dog
 *
 * Developer:
 *   wen.gu , 2020-08-19
 *
 * TODO:
 *
 ******************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __DOG_MICRO_SERVICE_CONTAINER_H__
#define __DOG_MICRO_SERVICE_CONTAINER_H__
#include <map>
#include <string>
#include <vector>

#include "dog_types.h"
#include "service/dog_service.h"

namespace dog
{
/******************************************************************************
 **    MACROS
 ******************************************************************************/


/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/

class MicroService;
/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/


class DOG_CLASS MicroServiceContainer : public Service
{
public:

    MicroServiceContainer();

    virtual ~MicroServiceContainer();
public:
    /**
     *  [in]  serviceName: the name of service
     *  [in]  comType:  the type of communication(e.g. dbus, cm an so on)
     */
    virtual DogErrc initialize(const std::string& serviceName, const std::string& comType) override;
    virtual DogErrc start() override;
    virtual DogErrc stop() override;
public:
    /** the life cycle of current micro service will be trusteeship by container(e.g. delete ) */
    virtual bool registerMicroService(MicroService* srv);

    /** auto load micro service component with plugin manager */
    virtual bool registerMicroService(const std::string& srvName);

    /** auto load micro services component with plugin manager */
    virtual bool registerMicroService(const std::vector<std::string>& srvNames,  bool ignoreError = true);

    /** unregister and release all micro service in current container */
    virtual void clear(); /** only when stop state can clear micro services */

    virtual MicroService* find(const std::string& srvName);

private:
    class impl;
    std::unique_ptr<impl> mImpl;
};

} /** namespace dog */

#endif /** !__DOG_MICRO_SERVICE_CONTAINER_H__ */

